COVID-19 statistics and trend

In [1]:
import pandas as pd
import os
import plotly.graph_objects as go
import plotly.io as pio
import plotly.offline as py
from scipy.optimize import curve_fit
from datetime import datetime
import re
import warnings
warnings.simplefilter('ignore')
In [2]:
pd.set_option("display.max_rows", 250)
In [3]:
pio.renderers.default = 'notebook'
In [4]:
from datetime import datetime

now = datetime.now()

current_time = now.strftime("%d-%m-%Y %H:%M")
print("Updated on", current_time, "h")
Updated on 16-08-2020 12:00 h
In [5]:
################################ Loading xls
In [6]:
url = "https://www.ecdc.europa.eu/sites/default/files/documents/COVID-19-geographic-disbtribution-worldwide.xlsx"
In [7]:
cases = pd.read_excel(url)
In [8]:
#filepath = "C:\\Users\\edidd\\Documents\\Ubiqum\\Data Analytics Course\\covid19\\data\\"
In [9]:
#cases = pd.read_excel(os.path.join(filepath, "COVID-19-geographic-disbtribution-worldwide-2020-04-23.xlsx"))
In [10]:
# filepath2 = "C:\\Users\\edidd\\Documents\\covid19_JHU_CSSE\\COVID-19\\"
In [11]:
# data_jhu= pd.read_csv(os.path.join(filepath2, "who_covid_19_situation_reports\\who_covid_19_sit_rep_time_series\\who_covid_19_sit_rep_time_series.csv"))
In [12]:
############################# Data wrangling
In [13]:
cases.dateRep = pd.to_datetime(cases.dateRep, format="%Y-%m-%d")
In [14]:
cases = cases.rename(columns= {
    "dateRep": "date", 
    "countriesAndTerritories": "country", 
    "cases": "newcases", 
    "deaths": "newdeaths"})
In [15]:
cases = cases.sort_values(by=["country", "date"])
In [16]:
cases["cumcases"]= cases.groupby("country")["newcases"].cumsum()
In [17]:
######################### Deleting rows with 0 cumulative cases
In [18]:
cases= cases.loc[cases.cumcases != 0,:]
In [19]:
cases= cases.set_index("country")

Summary

In [20]:
# Grouping by country
In [21]:
cases_total= cases.groupby(["country"]).sum().sort_values(by= ["newcases"], ascending= False)
In [22]:
cases_total= cases_total.rename(columns= {"newcases": "total_cases", "newdeaths": "total_deaths"})
In [23]:
cases_total= cases_total.drop(["day", "month", "year", "popData2019", "cumcases", "Cumulative_number_for_14_days_of_COVID-19_cases_per_100000"], axis= "columns")
In [24]:
cases_total["death_ratio"]= cases_total.total_deaths / cases_total.total_cases * 100
In [25]:
cases_total["population_2019"]= cases.groupby("country").max().popData2019
In [26]:
cases_total["cases_to_population"]= cases_total.total_cases / cases_total.population_2019 * 100
In [27]:
cases_total["cases_to_population"]= cases_total["cases_to_population"].map('{:,.2f}%'.format)
In [28]:
cases_total["death_ratio"]= cases_total["death_ratio"].map('{:,.2f}%'.format)

Global total of confirmed cases

21213649

Global total of deaths

In [30]:
cases_total.total_deaths.sum()
Out[30]:
760421

Totals per country

In [31]:
fig = go.Figure(data= [go.Bar(x= cases_total.index, 
                              y= cases_total.total_cases.head(10), 
                              text= "*" + cases_total.cases_to_population, 
                              textposition='auto')
                      ]
               )
fig.update_layout(title= "Total confirmed cases per country - top 10", 
                  xaxis_title= "* Showing percentage of country's population")
fig.show()
In [32]:
morethan1000 = cases_total.loc[cases_total.total_cases >= 1000, :].copy()
In [33]:
morethan1000["death_ratio"] = morethan1000.total_deaths / morethan1000.total_cases
In [34]:
fig= go.Figure()

fig.add_trace(go.Histogram(x= morethan1000.death_ratio, 
                           histnorm= "probability",
                           xbins=dict(
                               start=0,
                               end=morethan1000.death_ratio.max(),
                               size=.01
                           )
                          )
             )

fig.update_layout(title= "Global distribution of death ratio", 
                 xaxis=dict(tickformat= "%", tickangle=0, 
                            title='* Only countries with more than 999 reported cases are considered'))

pio.show(fig)

Complete list

total_cases total_deaths death_ratio population_2019 cases_to_population
country
United_States_of_America 5313080 168446 3.17% 3.290649e+08 1.61%
Brazil 3275520 106523 3.25% 2.110495e+08 1.55%
India 2526192 49036 1.94% 1.366418e+09 0.18%
Russia 912823 15498 1.70% 1.458723e+08 0.63%
South_Africa 579140 11556 2.00% 5.855827e+07 0.99%
Peru 516296 25856 5.01% 3.251046e+07 1.59%
Mexico 511369 55908 10.93% 1.275755e+08 0.40%
Colombia 445111 14492 3.26% 5.033944e+07 0.88%
Chile 382111 10340 2.71% 1.895204e+07 2.02%
Spain 342813 28617 8.35% 4.693706e+07 0.73%
Iran 338825 19331 5.71% 8.291389e+07 0.41%
United_Kingdom 316367 41357 13.07% 6.664711e+07 0.47%
Saudi_Arabia 295902 3338 1.13% 3.426853e+07 0.86%
Pakistan 288047 6162 2.14% 2.165653e+08 0.13%
Argentina 276072 5428 1.97% 4.478068e+07 0.62%
Bangladesh 271881 3591 1.32% 1.630462e+08 0.17%
Italy 252809 35234 13.94% 6.035955e+07 0.42%
Turkey 246861 5934 2.40% 8.200388e+07 0.30%
Germany 222828 9231 4.14% 8.301921e+07 0.27%
France 212211 30406 14.33% 6.701288e+07 0.32%
Iraq 168290 5709 3.39% 3.930979e+07 0.43%
Philippines 153660 2442 1.59% 1.081166e+08 0.14%
Indonesia 135123 6021 4.46% 2.706256e+08 0.05%
Canada 121652 9020 7.41% 3.741104e+07 0.33%
Kazakhstan 119781 1480 1.24% 1.855143e+07 0.65%
Qatar 114532 190 0.17% 2.832071e+06 4.04%
Ecuador 99409 6030 6.07% 1.737366e+07 0.57%
Bolivia 96459 3884 4.03% 1.151310e+07 0.84%
Egypt 96220 5124 5.33% 1.003881e+08 0.10%
Israel 91080 665 0.73% 8.519373e+06 1.07%
China 89214 4701 5.27% 1.433784e+09 0.01%
Ukraine 87872 2011 2.29% 4.399364e+07 0.20%
Dominican_Republic 84488 1409 1.67% 1.073896e+07 0.79%
Sweden 84294 5783 6.86% 1.023018e+07 0.82%
Oman 82743 557 0.67% 4.974992e+06 1.66%
Panama 79402 1734 2.18% 4.246440e+06 1.87%
Belgium 77020 9924 12.88% 1.145552e+07 0.67%
Kuwait 75185 494 0.66% 4.207077e+06 1.79%
Belarus 69308 603 0.87% 9.452409e+06 0.73%
Romania 68046 2904 4.27% 1.941446e+07 0.35%
United_Arab_Emirates 63819 359 0.56% 9.770526e+06 0.65%
Netherlands 61785 6158 9.97% 1.728216e+07 0.36%
Guatemala 61428 2341 3.81% 1.758148e+07 0.35%
Singapore 55580 27 0.05% 5.804343e+06 0.96%
Poland 55319 1858 3.36% 3.797281e+07 0.15%
Portugal 53783 1772 3.29% 1.027662e+07 0.52%
Japan 53577 1085 2.03% 1.268603e+08 0.04%
Honduras 49467 1548 3.13% 9.746115e+06 0.51%
Nigeria 48445 973 2.01% 2.009636e+08 0.02%
Bahrain 46052 168 0.36% 1.641164e+06 2.81%
Ghana 42063 231 0.55% 3.041786e+07 0.14%
Kyrgyzstan 41373 1491 3.60% 6.415851e+06 0.64%
Armenia 41299 814 1.97% 2.957728e+06 1.40%
Morocco 39241 611 1.56% 3.647177e+07 0.11%
Algeria 37664 1351 3.59% 4.305305e+07 0.09%
Switzerland 37580 1715 4.56% 8.544527e+06 0.44%
Afghanistan 37431 1363 3.64% 3.804176e+07 0.10%
Uzbekistan 34251 223 0.65% 3.298172e+07 0.10%
Azerbaijan 34018 504 1.48% 1.004772e+07 0.34%
Venezuela 31381 266 0.85% 2.851583e+07 0.11%
Moldova 29483 884 3.00% 4.043258e+06 0.73%
Kenya 29334 465 1.59% 5.257397e+07 0.06%
Serbia 29233 665 2.27% 6.963764e+06 0.42%
Ethiopia 27242 492 1.81% 1.120787e+08 0.02%
Ireland 26955 1774 6.58% 4.904240e+06 0.55%
Costa_Rica 26931 281 1.04% 5.047561e+06 0.53%
Nepal 25551 99 0.39% 2.860872e+07 0.09%
Puerto_Rico 25128 311 1.24% 2.933404e+06 0.86%
Austria 22951 725 3.16% 8.858775e+06 0.26%
Australia 22743 375 1.65% 2.520320e+07 0.09%
El_Salvador 22314 595 2.67% 6.453550e+06 0.35%
Palestine 21056 116 0.55% 4.981422e+06 0.42%
Czechia 19693 394 2.00% 1.064980e+07 0.18%
Cameroon 18469 401 2.17% 2.587639e+07 0.07%
Cote_dIvoire 16935 106 0.63% 2.571655e+07 0.07%
Bosnia_and_Herzegovina 15534 464 2.99% 3.300998e+06 0.47%
Denmark 15379 621 4.04% 5.806081e+06 0.26%
South_Korea 15039 305 2.03% 5.122532e+07 0.03%
Bulgaria 14243 492 3.45% 7.000039e+06 0.20%
Madagascar 13643 164 1.20% 2.696931e+07 0.05%
North_Macedonia 12546 535 4.26% 2.077132e+06 0.60%
Sudan 12162 793 6.52% 4.281324e+07 0.03%
Senegal 11872 249 2.10% 1.629636e+07 0.07%
Kosovo 11130 381 3.42% 1.798506e+06 0.62%
Norway 9850 261 2.65% 5.328212e+06 0.18%
Democratic_Republic_of_the_Congo 9604 238 2.48% 8.679057e+07 0.01%
Malaysia 9149 125 1.37% 3.194979e+07 0.03%
Paraguay 9077 108 1.19% 7.044639e+06 0.13%
Zambia 9021 256 2.84% 1.786103e+07 0.05%
Guinea 8260 50 0.61% 1.277125e+07 0.06%
Gabon 8225 51 0.62% 2.172578e+06 0.38%
Lebanon 8045 94 1.17% 6.855709e+06 0.12%
Tajikistan 7989 63 0.79% 9.321023e+06 0.09%
Haiti 7831 196 2.50% 1.126308e+07 0.07%
Finland 7700 333 4.32% 5.517919e+06 0.14%
Luxembourg 7405 122 1.65% 6.138940e+05 1.21%
Libya 7327 139 1.90% 6.777453e+06 0.11%
Albania 7117 219 3.08% 2.862427e+06 0.25%
Greece 6632 223 3.36% 1.072460e+07 0.06%
Mauritania 6622 157 2.37% 4.525698e+06 0.15%
Croatia 6258 163 2.60% 4.076246e+06 0.15%
Maldives 5572 22 0.39% 5.309570e+05 1.05%
Djibouti 5367 59 1.10% 9.735570e+05 0.55%
Zimbabwe 5072 128 2.52% 1.464547e+07 0.03%
Malawi 4988 156 3.13% 1.862875e+07 0.03%
Hungary 4853 607 12.51% 9.772756e+06 0.05%
Equatorial_Guinea 4821 83 1.72% 1.355982e+06 0.36%
Central_African_Republic 4652 61 1.31% 4.745179e+06 0.10%
Nicaragua 4115 128 3.11% 6.545503e+06 0.06%
Montenegro 3930 73 1.86% 6.221820e+05 0.63%
Congo 3745 60 1.60% 5.380504e+06 0.07%
Namibia 3726 31 0.83% 2.494524e+06 0.15%
Eswatini 3670 68 1.85% 1.148133e+06 0.32%
Thailand 3376 58 1.72% 6.962558e+07 0.00%
Somalia 3250 93 2.86% 1.544291e+07 0.02%
Cuba 3229 88 2.73% 1.133348e+07 0.03%
Cape_Verde 3136 33 1.05% 5.499360e+05 0.57%
Sri_Lanka 2886 11 0.38% 2.132373e+07 0.01%
Suriname 2838 41 1.44% 5.813630e+05 0.49%
Slovakia 2801 31 1.11% 5.450421e+06 0.05%
Mozambique 2708 19 0.70% 3.036604e+07 0.01%
Mali 2597 125 4.81% 1.965802e+07 0.01%
South_Sudan 2482 47 1.89% 1.106211e+07 0.02%
Slovenia 2369 124 5.23% 2.080908e+06 0.11%
Lithuania 2352 81 3.44% 2.794184e+06 0.08%
Rwanda 2293 8 0.35% 1.262694e+07 0.02%
Estonia 2177 63 2.89% 1.324820e+06 0.16%
Guinea_Bissau 2052 29 1.41% 1.920917e+06 0.11%
Benin 2001 38 1.90% 1.180115e+07 0.02%
Iceland 1983 10 0.50% 3.569910e+05 0.56%
Sierra_Leone 1947 69 3.54% 7.813207e+06 0.02%
Tunisia 1903 53 2.79% 1.169472e+07 0.02%
Yemen 1858 528 28.42% 2.916192e+07 0.01%
Angola 1815 83 4.57% 3.182530e+07 0.01%
Gambia 1623 50 3.08% 2.347696e+06 0.07%
Syria 1515 58 3.83% 1.707013e+07 0.01%
Uruguay 1421 38 2.67% 3.461731e+06 0.04%
Uganda 1385 12 0.87% 4.426959e+07 0.00%
Jordan 1329 11 0.83% 1.010170e+07 0.01%
Cyprus 1318 20 1.52% 8.758990e+05 0.15%
Latvia 1308 32 2.45% 1.919968e+06 0.07%
Georgia 1306 17 1.30% 3.996762e+06 0.03%
New_Zealand 1258 22 1.75% 4.783062e+06 0.03%
Liberia 1252 82 6.55% 4.937374e+06 0.03%
Burkina_Faso 1240 54 4.35% 2.032138e+07 0.01%
Botswana 1214 3 0.25% 2.303703e+06 0.05%
Malta 1175 9 0.77% 4.935590e+05 0.24%
Niger 1165 69 5.92% 2.331072e+07 0.00%
Togo 1124 26 2.31% 8.082359e+06 0.01%
Bahamas 1119 17 1.52% 3.894860e+05 0.29%
Jamaica 1082 14 1.29% 2.948277e+06 0.04%
Andorra 989 53 5.36% 7.617700e+04 1.30%
Aruba 973 4 0.41% 1.063100e+05 0.92%
Chad 951 76 7.99% 1.594688e+07 0.01%
Vietnam 930 21 2.26% 9.646211e+07 0.00%
Lesotho 884 25 2.83% 2.125267e+06 0.04%
Sao_Tome_and_Principe 883 15 1.70% 2.150480e+05 0.41%
Western_Sahara 766 1 0.13% 5.824580e+05 0.13%
United_States_Virgin_Islands 734 9 1.23% 1.045790e+05 0.70%
San_Marino 719 42 5.84% 3.445300e+04 2.09%
Cases_on_an_international_conveyance_Japan 696 7 1.01% NaN nan%
Guyana 649 22 3.39% 7.827750e+05 0.08%
United_Republic_of_Tanzania 509 21 4.13% 5.800546e+07 0.00%
Guam 502 5 1.00% 1.672950e+05 0.30%
Taiwan 482 7 1.45% 2.377388e+07 0.00%
Trinidad_and_Tobago 412 8 1.94% 1.394969e+06 0.03%
Burundi 412 1 0.24% 1.153058e+07 0.00%
Comoros 399 7 1.75% 8.508910e+05 0.05%
Belize 388 3 0.77% 3.903510e+05 0.10%
Myanmar 374 6 1.60% 5.404542e+07 0.00%
Faroe_Islands 362 0 0.00% 4.867700e+04 0.74%
Jersey 356 31 8.71% 1.077960e+05 0.33%
Mauritius 344 10 2.91% 1.269670e+06 0.03%
Isle_of_Man 336 24 7.14% 8.458900e+04 0.40%
Mongolia 298 0 0.00% 3.225166e+06 0.01%
Eritrea 285 0 0.00% 3.497117e+06 0.01%
Turks_and_Caicos_islands 274 2 0.73% 3.819400e+04 0.72%
Cambodia 273 0 0.00% 1.648654e+07 0.00%
Papua_New_Guinea 271 3 1.11% 8.776119e+06 0.00%
Sint_Maarten 269 17 6.32% 4.238900e+04 0.63%
Guernsey 252 13 5.16% 6.446800e+04 0.39%
Gibraltar 206 0 0.00% 3.370600e+04 0.61%
Cayman_Islands 203 1 0.49% 6.494800e+04 0.31%
French_Polynesia 166 0 0.00% 2.792850e+05 0.06%
Bermuda 159 9 5.66% 6.250800e+04 0.25%
Barbados 148 7 4.73% 2.870210e+05 0.05%
Monaco 146 4 2.74% 3.308500e+04 0.44%
Brunei_Darussalam 142 3 2.11% 4.332960e+05 0.03%
Bhutan 133 0 0.00% 7.630940e+05 0.02%
Seychelles 127 0 0.00% 9.774100e+04 0.13%
Antigua_and_Barbuda 93 3 3.23% 9.711500e+04 0.10%
Liechtenstein 91 1 1.10% 3.837800e+04 0.24%
Saint_Vincent_and_the_Grenadines 57 0 0.00% 1.105930e+05 0.05%
Northern_Mariana_Islands 50 2 4.00% 5.721300e+04 0.09%
Curaçao 32 1 3.12% 1.634230e+05 0.02%
Fiji 27 1 3.70% 8.899550e+05 0.00%
Saint_Lucia 25 0 0.00% 1.827950e+05 0.01%
Timor_Leste 25 0 0.00% 1.293120e+06 0.00%
Grenada 24 0 0.00% 1.120020e+05 0.02%
New_Caledonia 23 0 0.00% 2.827570e+05 0.01%
Laos 20 0 0.00% 7.169456e+06 0.00%
Dominica 18 0 0.00% 7.180800e+04 0.03%
Saint_Kitts_and_Nevis 17 0 0.00% 5.283400e+04 0.03%
Greenland 14 0 0.00% 5.666000e+04 0.02%
Falkland_Islands_(Malvinas) 13 0 0.00% 3.372000e+03 0.39%
Bonaire, Saint Eustatius and Saba 13 0 0.00% 2.598300e+04 0.05%
Montserrat 13 1 7.69% 4.991000e+03 0.26%
Holy_See 12 0 0.00% 8.150000e+02 1.47%
British_Virgin_Islands 9 1 11.11% 3.003300e+04 0.03%
Anguilla 3 0 0.00% 1.487200e+04 0.02%

Trends shown for countries with more than 999 reported cases. Double-click on a country name in the legend next to each figure, in order to show only the selected country.

In [36]:
cases_total= cases_total.sort_values("country")
In [37]:
country_list= cases_total.loc[cases_total.total_cases >= 1000, :].index
In [39]:
fig = go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases.loc[country].date, 
                             y= cases.loc[country].cumcases, 
                             mode= "markers",
                             name= country))
fig.update_layout(title="Cummulative cases per country")#, yaxis_type="log")
pio.show(fig)
In [41]:
# cases["growfactor"] = cases.newcases / cases.groupby("country")["newcases"].shift(1).fillna(0)

Exponential fitting

In [44]:
cases= cases.loc[cases.cumcases >= 20,:]
In [45]:
cases["datemin"] = cases.groupby("country")["date"].min()
In [46]:
cases["days"]= cases.date - cases.datemin
In [47]:
cases.days= cases.days.dt.days
In [48]:
def exponential_growth(x, a, c_o):
    return c_o*a**x
In [49]:
def country_fit(df, country):
    x= df.loc[country].days
    y= df.loc[country].cumcases
    popt, pcov= curve_fit(exponential_growth, x, y)
    return popt
In [50]:
popt_list= []
popt_df= pd.DataFrame(columns= ["A"])
In [51]:
for i, country in enumerate(country_list):
    popt_list.append(country_fit(cases, country))
    popt_df.loc[country]= popt_list[i][0]

Factor A of exponential growth (C = Co * A^d)

It can be interpreted as an average daily increase factor of total cases.

In [52]:
popt_df.sort_values("A", ascending= False)
Out[52]:
A
Gambia 1.099550
Bahamas 1.059680
Namibia 1.050803
Libya 1.050699
Zimbabwe 1.047621
Angola 1.041944
Suriname 1.041254
Costa_Rica 1.041242
Palestine 1.040337
Botswana 1.039343
Kyrgyzstan 1.038824
Venezuela 1.038645
Ethiopia 1.038437
Zambia 1.038392
Madagascar 1.037704
Syria 1.037024
Montenegro 1.036745
Colombia 1.035466
Kenya 1.035430
Argentina 1.035037
India 1.034335
Eswatini 1.033320
Malawi 1.032731
South_Africa 1.032443
Iraq 1.031896
Paraguay 1.031086
Uzbekistan 1.030770
Kazakhstan 1.030727
Kosovo 1.030173
Philippines 1.030168
Guatemala 1.030056
El_Salvador 1.029965
Bolivia 1.028451
Lebanon 1.028014
Mozambique 1.027488
Honduras 1.027286
Puerto_Rico 1.026407
Congo 1.025750
Bosnia_and_Herzegovina 1.025602
Cape_Verde 1.024568
Brazil 1.024561
Nepal 1.024435
Oman 1.024339
Albania 1.023874
Bulgaria 1.023843
Mexico 1.023615
Ghana 1.023607
Panama 1.023284
Dominican_Republic 1.023128
Benin 1.022998
Israel 1.022976
Azerbaijan 1.022916
Rwanda 1.022913
Indonesia 1.022694
Morocco 1.022460
Bangladesh 1.022454
Nigeria 1.021758
Cote_dIvoire 1.021727
Algeria 1.021686
Mauritania 1.021475
Equatorial_Guinea 1.021464
North_Macedonia 1.020740
Armenia 1.020126
Bahrain 1.020063
Yemen 1.019400
Egypt 1.019385
Ukraine 1.019123
Chile 1.019116
Nicaragua 1.019111
Saudi_Arabia 1.019034
Maldives 1.018849
Pakistan 1.018790
Liberia 1.018788
Peru 1.018755
Haiti 1.018700
Senegal 1.018590
Kuwait 1.018511
Gabon 1.018427
Moldova 1.018318
Romania 1.018207
Central_African_Republic 1.018118
Democratic_Republic_of_the_Congo 1.018045
Uganda 1.017794
Cameroon 1.017345
United_States_of_America 1.017236
Afghanistan 1.016593
Togo 1.016424
Japan 1.015996
Sudan 1.015970
Russia 1.015962
Qatar 1.015314
Ecuador 1.015304
Sierra_Leone 1.014798
Serbia 1.014731
South_Sudan 1.014728
Guinea 1.014515
United_Arab_Emirates 1.014383
Sweden 1.014247
Poland 1.014178
Sri_Lanka 1.014078
Australia 1.013941
Mali 1.013708
Singapore 1.013537
Iran 1.013533
Tajikistan 1.013471
Belarus 1.013339
Croatia 1.013041
Guinea_Bissau 1.012707
Djibouti 1.012658
Somalia 1.011756
Jamaica 1.011133
Czechia 1.011035
Georgia 1.010767
Canada 1.010724
Portugal 1.010504
Jordan 1.010204
Turkey 1.009890
United_Kingdom 1.009694
Greece 1.009674
Slovakia 1.009305
Cuba 1.009031
Uruguay 1.008999
Malaysia 1.008582
France 1.008376
Hungary 1.008359
Luxembourg 1.008255
Malta 1.008224
Denmark 1.008101
Burkina_Faso 1.008053
Netherlands 1.008040
Belgium 1.007952
Tunisia 1.007918
Finland 1.007721
Germany 1.007593
Spain 1.007591
Ireland 1.007450
Slovenia 1.007078
Thailand 1.007052
Italy 1.006925
Lithuania 1.006901
Austria 1.006779
Latvia 1.006644
Cyprus 1.006604
Switzerland 1.006272
Niger 1.006228
Norway 1.006039
South_Korea 1.005859
Estonia 1.005711
Iceland 1.004682
China 1.004052
New_Zealand 1.003662

Exponential fitting

In [53]:
fig= go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases.loc[country].days, 
                             y= cases.loc[country].cumcases, 
                             mode= "markers",
                             name= country))
    fig.add_trace(go.Scatter(x= cases.loc[country].days,
                             y= exponential_growth(cases.loc[country].days, *popt_list[i]),
                             mode= "lines",
                             name= "exponential fit"))
fig.update_layout(title= "Exponential fit per country")

pio.show(fig)

Change in the number of reported new cases

A positive change means an increase in the number of reported cases. A negative change means a decrease in the number of new cases, that means good news!

In [54]:
country_list= cases_total.loc[cases_total.total_cases >= 1000, :].index
In [55]:
cases["growspeed"]= cases.newcases - cases.groupby("country").newcases.shift(1).fillna(0)
In [56]:
fig= go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases.loc[country].date, 
                             y= cases.loc[country].growspeed, 
                             mode= "markers",
                             name= country))
fig.update_layout(title= "Daily change in number of new cases")

pio.show(fig)
In [57]:
#### Grow speed with different aggregations
In [58]:
cases= cases.reset_index()
In [59]:
cases= cases.set_index("date")
In [60]:
cases_2d= cases.groupby("country").resample(pd.Timedelta(days= 2)).sum().loc[:,["newcases"]]
In [61]:
cases_3d= cases.groupby("country").resample(pd.Timedelta(days= 3)).sum().loc[:,["newcases"]]
In [62]:
cases_4d= cases.groupby("country").resample(pd.Timedelta(days= 4)).sum().loc[:,["newcases"]]
In [63]:
cases_7d= cases.groupby("country").resample(pd.Timedelta(days= 7)).sum().loc[:,["newcases"]]
In [64]:
# Grow speed
In [65]:
cases_2d["growspeed"]= cases_2d.newcases - cases_2d.groupby("country").newcases.shift(1).fillna(0)
In [66]:
fig= go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases_2d.loc[country].index, 
                             y= cases_2d.loc[country].growspeed, 
                             mode= "markers",
                             name= country))
fig.update_layout(title= "Change in the number of new cases (2 days period)")
pio.show(fig)
In [67]:
cases_3d["growspeed"]= cases_3d.newcases - cases_3d.groupby("country").newcases.shift(1).fillna(0)
In [68]:
fig= go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases_3d.loc[country].index, 
                             y= cases_3d.loc[country].growspeed, 
                             mode= "markers",
                             name= country))
fig.update_layout(title= "Change in the number of new cases (3 days period)")

pio.show(fig)
In [69]:
cases_4d["growspeed"]= cases_4d.newcases - cases_4d.groupby("country").newcases.shift(1).fillna(0)
In [70]:
fig= go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases_4d.loc[country].index, 
                             y= cases_4d.loc[country].growspeed, 
                             mode= "markers",
                             name= country))
fig.update_layout(title= "Change in the number of new cases (4 days period)")
pio.show(fig)
In [71]:
cases_7d["growspeed"]= cases_7d.newcases - cases_7d.groupby("country").newcases.shift(1).fillna(0)
In [72]:
fig= go.Figure()
for i, country in enumerate(country_list):
    fig.add_trace(go.Scatter(x= cases_7d.loc[country].index, 
                             y= cases_7d.loc[country].growspeed, 
                             mode= "markers",
                             name= country))
fig.update_layout(title= "Change in the number of new cases (1 week period)")
pio.show(fig)
In [73]:
cases= cases.reset_index()
In [74]:
cases= cases.set_index("country")
In [75]:
#!jupyter nbconvert --to html --template toc2 EAP.ipynb